/*
 * Region.h
 *
 *  Created on: 22-Feb-2014
 *      Author: dev
 */

#ifndef REGION_H_
#define REGION_H_

#include <iostream>
#include <sstream>

#include "Rectangle.h"

using namespace std;

/* NOTE
 * implementation for rectangle derived region
 * this do not cover triangular region or skewed faces
 * can have more than four edges all vertical/horizontal
 *
 * useful methods for this class are origin(), top(), right(), bottom(), left()
 */

namespace tf {

class Region {
public:

	/*
	 * @brief require base region to begin with
	 */
	Region(Rectangle* rect);

	/* @brief	to know inside starting point of a region
	 * @return
	 */
	Point origin();

	/*
	 * @brief for a given x lower bounds of region
	 * @param	x a range inside region
	 * @return	-1 if x is not inside region
	 */
	int bottom(int x);

	/*
	 * @brief for a given x upper bounds of region
	 * @param	x a range inside region
	 * @return	-1 if x is not inside region
	 */
	int top(int x);

	/*
	 * @brief for a given y lower bound of region
	 * @param	y a range inside region
	 * @return	-1 if y is not inside region
	 */
	int left(int y);

	/*
	 * @brief for a given y upper bound of region
	 * @param	y a range inside region
	 * @return	-1 if y is not inside region
	 */
	int right(int y);

	// union boolean operations
	void add(Rectangle* rect);

	// substract boolean operation
	void remove(Rectangle* rect);

	/*
	 * @brief largest rectangle housing this region
	 */
	Rectangle bounds();

	bool interset(Region reg);

	virtual ~Region();

	string str();
private:

	/*
	 * bool parameter tells this rectangle forms a union
	 */
	std::vector<std::pair<Rectangle*, bool> > rects;
};

} /* namespace tf */
#endif /* REGION_H_ */
